<html>
<#include "../common/header.ftl" />
<script>
$(function(){
	
	$('#submit').on('click', function() {
		if (($("#type").val().trim()) == '') {
			tip('请填写名称！！！');
			return;
		}
		let obj = $("#type").val();
		console.log(JSON.parse(JSON.stringify(obj)))
		$.ajax({
			url : "news?method=addType",
			type : "POST",
			data : {type:obj},
			success : function(res) {
				let data = JSON.parse(res)
				if (data.code === 0) {
					tip("添加"+data.msg)
					setTimeout("location.reload()",500)
				}
				else{
					tip(data.msg)
				}
			},
			error : function(res) {
				console.log("res", res);
			}
		});
		/* console.log('data', $('form').serializeArray()) */
	})
})
function tip (msg){
		$("#warn").text(msg)
		$("#modal-282051").click()
	}
</script>
</head>

<#if Session.user ?? && user.role==1>
<body style="margin-left: 200px">

	<div id="wrapper" class="toggled"><#include "../common/nav.ftl"
		/></div>
	<#else> </#if>


	<div class="container">
	
		<div class="row clearfix">
			<div class="col-md-12 column">
		

				<#include "../common/bread.ftl"/>
			<#include "../modal/addType.ftl"/>
			<#include "../modal/tips.ftl"/>

 <a id="modal-282051" href="#modal-warns" style="display:none" role="button" class="" data-toggle="modal"></a>
		
				<div class="list-group ">
					<#if lists ??>
						<#if types ??>
					<button class="btn btn-warning" type="button">
						<em class="glyphicon glyphicon-align-left"></em> 分类：
					</button>
				
					<#list types as item> <a href="news?method=list&type=${item }"><button
							class="btn btn-info" type="button">${item }</button></a> </#list>
					</#if>
					<#if Session.user.role ?? &&
					Session.user.role == 1>
					<a id="modal-282051" href="#modal-addType"  role="button"  data-toggle="modal" class="btn btn-warning" type="button">
						<em class="glyphicon glyphicon-plus"></em>  
					</a>
					</#if>
					<br>
					<br>
					<button class="btn btn-primary" type="button">
						<em class="glyphicon glyphicon-align-left"></em> 排序：
					</button>
					<a href="news?method=sort&key=news_click"><button
							class="btn btn-info" type="button">热度</button></a>
					<a href="news?method=sort&key=news_id"><button
							class="btn btn-info" type="button">时间</button></a>
							<hr />	
					<#if (lists.data?size>0)>
					<#else>
					<div class="list-group-item  list-group-item-warning">
						<p><h1><b>没有查到数据哦!</b></h1></p>
					</div>
					
					</#if>
					<#list lists.data as item> 
					
					<#if Session.user.role ?? &&
					Session.user.role == 0> <#if item.newsState == 1> <a
						href="news?method=detail_page&id=${item.newsId }"
						class="list-group-item list-group-item-success ">
						<h4 class="list-group-item-heading">
							<div <#if item.newsClick gt 100>
								style="color:red"						
							</#if>
							>${item.newsName }
							_By【${item.newsAuthor }】 
							<#if item.newsClick gt 100 && item.newsClick lte 400>
							<span class="glyphicon glyphicon-fire" />
							</#if>
							<#if item.newsClick gt 401 && item.newsClick lte 800>
							<span class="glyphicon glyphicon-fire" />
							<span class="glyphicon glyphicon-fire" />
							</#if>
							<#if item.newsClick gt 801>
							<span class="glyphicon glyphicon-fire" />
							<span class="glyphicon glyphicon-fire" />
							<span class="glyphicon glyphicon-fire" />
							</#if>
							</div>
							
							 <#if item.uId == Session.user.id>
									 <span style="float:right">【我的比赛】</span>
								</#if>
							</h4>
						<p style="display:block;padding:5px"><span style="font-size:25px" class="glyphicon glyphicon-eye-open"/><span class="badge" style="font-size:15px">${item.newsClick }</span><span style="font-size:25px" class="glyphicon glyphicon-eye-open"/></p>
						<p>
							<#if item.newsType ?? && item.newsType?size gt 0 > <#list
							item.newsType as _item> <span class="label label-info"
								style="margin-right: 0px; margin-left: 5px">${ _item}</span>
							</#list> <#else> <span class="label label-info"
								style="margin-right: 0px; margin-left: 5px">其他</span> </#if>
						</p> <span class="label label-primary">${item.publisher } </span> <span
						class="label label-primary">${item.createtime?string("yyyy-MM-dd HH:mm:ss zzzz")}</span>
					</a> </#if> <#else> <a
						href="news?method=detail_page&id=${item.newsId }"
						class="list-group-item 
							<#if item.newsState ==0>	list-group-item-warning</#if>
						<#if item.newsState ==1>	list-group-item-success</#if>
						<#if item.newsState ==2> list-group-item-danger</#if>
						"
						>
						<h4 class="list-group-item-heading"
							
						><div <#if item.newsClick gt 100>
								style="color:red"						
							</#if>>${item.newsName }
							<#if item.newsClick gt 100 && item.newsClick lte 400>
							<span class="glyphicon glyphicon-fire" />
							</#if>
							<#if item.newsClick gt 401 && item.newsClick lte 800>
							<span class="glyphicon glyphicon-fire" />
							<span class="glyphicon glyphicon-fire" />
							</#if>
							<#if item.newsClick gt 801>
							<span class="glyphicon glyphicon-fire" />
							<span class="glyphicon glyphicon-fire" />
							<span class="glyphicon glyphicon-fire" />
							</#if>
							</div>
							<span style="float: right">
							 <#if
								item.newsState ==0>  <#if item.uId == Session.user.id>
									 【我的比赛】
								</#if>【待审核】</#if> 
								<#if item.newsState ==1>  <#if item.uId == Session.user.id>
									 【我的比赛】
								</#if>【已审核】</#if> 
								 <#if item.newsState ==2>
								  <#if item.uId == Session.user.id>
									 【我的比赛】
								</#if> 【已废弃】
								</#if> </span>
								
								 
								 </span>
						</h4>
						<p style="padding:5px;height:35px;"><span style="font-size:20px;vertical-align:middle;" class="glyphicon glyphicon-eye-open"/><span style="font-family: 'Microsoft YaHei';padding:10px"><b>${item.newsClick }</b></span></p>
						<p>
							<#if item.newsType ?? && item.newsType?size gt 0 > <#list
							item.newsType as _item> <span class="label label-info"
								style="margin-right: 0px; margin-left: 5px">${ _item}</span>
							</#list> <#else> <span class="label label-info"
								style="margin-right: 0px; margin-left: 5px">其他</span> </#if>
						</p> 
						<span class="label label-primary">${item.publisher } </span> <span
						class="label label-primary">${item.createtime }
						</span>
							
					</a> </#if>
					
					 </#list>
					<#else>
					<div class="list-group-item  list-group-item-warning">
						<p><h1><b>没有查到数据哦!</b></h1></p>
					</div>
					</#if>
					
				</div>

				<#--
				<table class="table table-striped">
					<thead>
						<tr>
							<th>编号</th>
							<th>名称</th>
							<th>作者</th>
							<th>发布人</th>
							<th>类型</th>
							<th>关键字</th>
							<th>点击量</th>
							<th>创建时间</th>
							<th colspan="2">操作</th>
						</tr>
					</thead>
					<tbody>
						<#list lists.data as item> <#if Session.user.role ?? &&
						Session.user.role == 0> <#if item.newsState == 1>
						<tr class="success">
							<td>${item.newsId }</td>
							<td>${item.newsName }</td>
							<td>${item.newsAuthor }</td>
							<td>${item.publisher  }</td>
							<td><#if item.newsType ==1>科普</#if> <#if item.newsType
								==2>体育</#if> <#if item.newsType ==3>财经</#if> <#if item.newsType
								==4>生活</#if></td>
							<td>${item.newsKeywords!"" }</td>
							<td>${item.newsClick }</td>
							<td>${item.createtime }</td>
							<td><a href="news?method=detail_page&id=${item.newsId }">查看</a>
								<#if Session.user.role ?? && Session.user.role == 1 > <a
								href="#">删除</a> </#if></td>
						</tr>
						</#if> <#else> <#if item.newsState ==0>
						<tr class="warning"></#if> <#if item.newsState ==1>
						<tr class="success"></#if> <#if item.newsState ==2>
						<tr style="background: rgba(255, 69, 0, 0.4)">
							</#if>
							<td>${item.newsId }</td>
							<td>${item.newsName }</td>
							<td>${item.newsAuthor }</td>
							<td>${item.publisher  }</td>
							<td><#if item.newsType ==1>科普</#if> <#if item.newsType
								==2>体育</#if> <#if item.newsType ==3>财经</#if> <#if item.newsType
								==4>生活</#if></td>
							<td>${item.newsKeywords!"" }</td>
							<td>${item.newsClick }</td>

							<td><#if item.newsState ==1>已发布</#if> <#if item.newsState
								==0>待审核</#if> <#if item.newsState ==2><span style="color: red;"><b>已废弃</b></span></#if>
							</td>

							<td>${item.createtime }</td>

							<td><a href="news?method=detail_page&id=${item.newsId }">查看</a>
								<#if Session.user.role ?? && Session.user.role == 1 > <a
								href="#">删除</a> </#if></td>
						</tr>
						</#if> </#list>
					</tbody>
				</table>
				-->
			</div>
			<div class="col-md-12 column">
				<ul class="pagination pull-right">
					<#if lists.pageNo lte 1>
					<li class="disabled"><a href="#">上一页</a></li> <#else >
					<li><a
					<#if type ?? && type == "news_click" >
						href="news?method=sort&page=${lists.pageNo - 1}&size=${lists.pageSize}&key=news_click"
					<#elseif type ?? && type == "news_id" >
						href="news?method=sort&page=${lists.pageNo - 1}&size=${lists.pageSize}&key=news_id"
					<#elseif newsType ?? >
						href="news?method=list&page=${lists.pageNo - 1}&size=${lists.pageSize}&type=${newsType }"
					<#else>
						href="news?method=list&page=${lists.pageNo - 1}&size=${lists.pageSize}"
					</#if>						
						>上一页</a>
					</li> </#if> <#list 1..lists.totalPage as index> <#if lists.pageNo ==
					index>
					<li class="disabled"><a href="#">${index}</a></li> <#else>
					<li><a
						<#if type ?? && type == "news_click" >
						href="news?method=sort&page=${index}&size=${lists.pageSize}&key=news_click"
					<#elseif type ?? && type == "news_id" >
						href="news?method=sort&page=${index}&size=${lists.pageSize}&key=news_id"
					<#elseif newsType ?? >
						href="news?method=list&page=${index}&size=${lists.pageSize}&type=${newsType }"
					<#else>
						href="news?method=list&page=${index}&size=${lists.pageSize}"	
					</#if>
						>${index}</a>
					</li> </#if> </#list> <#if lists.pageNo gte lists.totalPage>
					<li class="disabled"><a href="#">下一页</a></li> <#else >
					<li><a
					<#if type ?? && type == "news_click" >
						href="news?method=sort&page=${lists.pageNo + 1}&size=${lists.pageSize}&key=news_click"
					<#elseif type ?? && type == "news_id" >
						href="news?method=sort&page=${lists.pageNo + 1}&size=${lists.pageSize}&key=news_id"
					<#elseif newsType ?? >
						href="news?method=list&page=${lists.pageNo + 1}&size=${lists.pageSize}&type=${newsType }"
					<#else>
						href="news?method=list&page=${lists.pageNo + 1}&size=${lists.pageSize}"	
					</#if>
						>下一页</a>
					</li> </#if>
				</ul>
			</div>

		</div>
	</div>
		<script src="static/js/3.1.0bootstrap.min.js"></script>
</body>
</html>